.class public Lorg/microemu/device/ui/EventDispatcher;
.super Ljava/lang/Object;
.source "EventDispatcher.java"

# interfaces
.implements Ljava/lang/Runnable;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lorg/microemu/device/ui/EventDispatcher$RunnableEvent;,
        Lorg/microemu/device/ui/EventDispatcher$HideNotifyEvent;,
        Lorg/microemu/device/ui/EventDispatcher$ShowNotifyEvent;,
        Lorg/microemu/device/ui/EventDispatcher$PointerEvent;,
        Lorg/microemu/device/ui/EventDispatcher$PaintEvent;,
        Lorg/microemu/device/ui/EventDispatcher$Event;
    }
.end annotation


# static fields
.field public static final EVENT_DISPATCHER_NAME:Ljava/lang/String; = "event-thread"


# instance fields
.field private volatile cancelled:Z

.field private head:Lorg/microemu/device/ui/EventDispatcher$Event;

.field private scheduledPaintEvent:Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

.field private scheduledPointerDraggedEvent:Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

.field private serviceRepaintsLock:Ljava/lang/Object;

.field private tail:Lorg/microemu/device/ui/EventDispatcher$Event;


# direct methods
.method public constructor <init>()V
    .locals 2

    .prologue
    const/4 v1, 0x0

    .line 45
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 33
    const/4 v0, 0x0

    iput-boolean v0, p0, Lorg/microemu/device/ui/EventDispatcher;->cancelled:Z

    .line 35
    iput-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->head:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 37
    iput-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->tail:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 39
    iput-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPaintEvent:Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    .line 41
    iput-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPointerDraggedEvent:Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    .line 43
    new-instance v0, Ljava/lang/Object;

    invoke-direct {v0}, Ljava/lang/Object;-><init>()V

    iput-object v0, p0, Lorg/microemu/device/ui/EventDispatcher;->serviceRepaintsLock:Ljava/lang/Object;

    .line 46
    return-void
.end method


# virtual methods
.method public final cancel()V
    .locals 1

    .prologue
    .line 89
    const/4 v0, 0x1

    iput-boolean v0, p0, Lorg/microemu/device/ui/EventDispatcher;->cancelled:Z

    .line 90
    monitor-enter p0

    .line 91
    :try_start_0
    invoke-virtual {p0}, Ljava/lang/Object;->notifyAll()V

    .line 92
    monitor-exit p0

    .line 93
    return-void

    .line 92
    :catchall_0
    move-exception v0

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v0
.end method

.method protected post(Lorg/microemu/device/ui/EventDispatcher$Event;)V
    .locals 0
    .parameter "event"

    .prologue
    .line 144
    invoke-virtual {p1}, Lorg/microemu/device/ui/EventDispatcher$Event;->run()V

    .line 145
    return-void
.end method

.method public put(Ljava/lang/Runnable;)V
    .locals 1
    .parameter "runnable"

    .prologue
    .line 123
    new-instance v0, Lorg/microemu/device/ui/EventDispatcher$RunnableEvent;

    invoke-direct {v0, p0, p1}, Lorg/microemu/device/ui/EventDispatcher$RunnableEvent;-><init>(Lorg/microemu/device/ui/EventDispatcher;Ljava/lang/Runnable;)V

    invoke-virtual {p0, v0}, Lorg/microemu/device/ui/EventDispatcher;->put(Lorg/microemu/device/ui/EventDispatcher$Event;)V

    .line 124
    return-void
.end method

.method public put(Lorg/microemu/device/ui/EventDispatcher$Event;)V
    .locals 3
    .parameter "event"

    .prologue
    const/4 v2, 0x2

    .line 96
    monitor-enter p0

    .line 97
    :try_start_0
    instance-of v1, p1, Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    if-eqz v1, :cond_0

    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPaintEvent:Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    if-eqz v1, :cond_0

    .line 98
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPaintEvent:Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    check-cast p1, Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    .end local p1
    invoke-virtual {v1, p1}, Lorg/microemu/device/ui/EventDispatcher$PaintEvent;->merge(Lorg/microemu/device/ui/EventDispatcher$PaintEvent;)V

    .line 119
    :goto_0
    monitor-exit p0

    .line 120
    return-void

    .line 99
    .restart local p1
    :cond_0
    instance-of v1, p1, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    if-eqz v1, :cond_1

    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPointerDraggedEvent:Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    if-eqz v1, :cond_1

    move-object v0, p1

    check-cast v0, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    move-object v1, v0

    invoke-static {v1}, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;->access$000(Lorg/microemu/device/ui/EventDispatcher$PointerEvent;)S

    move-result v1

    if-ne v1, v2, :cond_1

    .line 101
    iget-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPointerDraggedEvent:Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    move-object v0, p1

    check-cast v0, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    move-object v1, v0

    invoke-static {v1}, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;->access$100(Lorg/microemu/device/ui/EventDispatcher$PointerEvent;)I

    move-result v1

    invoke-static {v2, v1}, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;->access$102(Lorg/microemu/device/ui/EventDispatcher$PointerEvent;I)I

    .line 102
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPointerDraggedEvent:Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    check-cast p1, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    .end local p1
    invoke-static {p1}, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;->access$200(Lorg/microemu/device/ui/EventDispatcher$PointerEvent;)I

    move-result v2

    invoke-static {v1, v2}, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;->access$202(Lorg/microemu/device/ui/EventDispatcher$PointerEvent;I)I

    goto :goto_0

    .line 119
    :catchall_0
    move-exception v1

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v1

    .line 104
    .restart local p1
    :cond_1
    :try_start_1
    instance-of v1, p1, Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    if-eqz v1, :cond_2

    .line 105
    move-object v0, p1

    check-cast v0, Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    move-object v1, v0

    iput-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPaintEvent:Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    .line 107
    :cond_2
    instance-of v1, p1, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    if-eqz v1, :cond_3

    move-object v0, p1

    check-cast v0, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    move-object v1, v0

    invoke-static {v1}, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;->access$000(Lorg/microemu/device/ui/EventDispatcher$PointerEvent;)S

    move-result v1

    if-ne v1, v2, :cond_3

    .line 108
    move-object v0, p1

    check-cast v0, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    move-object v1, v0

    iput-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPointerDraggedEvent:Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    .line 110
    :cond_3
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->tail:Lorg/microemu/device/ui/EventDispatcher$Event;

    if-eqz v1, :cond_4

    .line 111
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->tail:Lorg/microemu/device/ui/EventDispatcher$Event;

    iput-object p1, v1, Lorg/microemu/device/ui/EventDispatcher$Event;->next:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 113
    :cond_4
    iput-object p1, p0, Lorg/microemu/device/ui/EventDispatcher;->tail:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 114
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->head:Lorg/microemu/device/ui/EventDispatcher$Event;

    if-nez v1, :cond_5

    .line 115
    iput-object p1, p0, Lorg/microemu/device/ui/EventDispatcher;->head:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 117
    :cond_5
    invoke-virtual {p0}, Ljava/lang/Object;->notifyAll()V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_0
.end method

.method public run()V
    .locals 4

    .prologue
    .line 50
    :goto_0
    iget-boolean v2, p0, Lorg/microemu/device/ui/EventDispatcher;->cancelled:Z

    if-nez v2, :cond_6

    .line 51
    const/4 v1, 0x0

    .line 52
    .local v1, event:Lorg/microemu/device/ui/EventDispatcher$Event;
    monitor-enter p0

    .line 53
    :try_start_0
    iget-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->head:Lorg/microemu/device/ui/EventDispatcher$Event;

    if-eqz v2, :cond_5

    .line 54
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->head:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 55
    iget-object v2, v1, Lorg/microemu/device/ui/EventDispatcher$Event;->next:Lorg/microemu/device/ui/EventDispatcher$Event;

    iput-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->head:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 56
    iget-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->head:Lorg/microemu/device/ui/EventDispatcher$Event;

    if-nez v2, :cond_0

    .line 57
    const/4 v2, 0x0

    iput-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->tail:Lorg/microemu/device/ui/EventDispatcher$Event;

    .line 59
    :cond_0
    instance-of v2, v1, Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    if-eqz v2, :cond_1

    .line 60
    const/4 v2, 0x0

    iput-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPaintEvent:Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    .line 62
    :cond_1
    instance-of v2, v1, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    if-eqz v2, :cond_2

    move-object v0, v1

    check-cast v0, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    move-object v2, v0

    invoke-static {v2}, Lorg/microemu/device/ui/EventDispatcher$PointerEvent;->access$000(Lorg/microemu/device/ui/EventDispatcher$PointerEvent;)S

    move-result v2

    const/4 v3, 0x2

    if-ne v2, v3, :cond_2

    .line 63
    const/4 v2, 0x0

    iput-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPointerDraggedEvent:Lorg/microemu/device/ui/EventDispatcher$PointerEvent;

    .line 71
    :cond_2
    :goto_1
    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_1

    .line 73
    if-eqz v1, :cond_3

    .line 74
    invoke-virtual {p0, v1}, Lorg/microemu/device/ui/EventDispatcher;->post(Lorg/microemu/device/ui/EventDispatcher$Event;)V

    .line 77
    :cond_3
    iget-object v2, p0, Lorg/microemu/device/ui/EventDispatcher;->serviceRepaintsLock:Ljava/lang/Object;

    monitor-enter v2

    .line 78
    :try_start_1
    instance-of v3, v1, Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    if-eqz v3, :cond_4

    .line 79
    iget-object v3, p0, Lorg/microemu/device/ui/EventDispatcher;->serviceRepaintsLock:Ljava/lang/Object;

    invoke-virtual {v3}, Ljava/lang/Object;->notify()V

    .line 81
    :cond_4
    monitor-exit v2

    goto :goto_0

    :catchall_0
    move-exception v3

    monitor-exit v2
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    throw v3

    .line 67
    :cond_5
    :try_start_2
    invoke-virtual {p0}, Ljava/lang/Object;->wait()V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_1
    .catch Ljava/lang/InterruptedException; {:try_start_2 .. :try_end_2} :catch_0

    goto :goto_1

    .line 68
    :catch_0
    move-exception v2

    goto :goto_1

    .line 71
    :catchall_1
    move-exception v2

    :try_start_3
    monitor-exit p0
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_1

    throw v2

    .line 83
    .end local v1           #event:Lorg/microemu/device/ui/EventDispatcher$Event;
    :cond_6
    return-void
.end method

.method public serviceRepaints()V
    .locals 2

    .prologue
    .line 127
    iget-object v0, p0, Lorg/microemu/device/ui/EventDispatcher;->serviceRepaintsLock:Ljava/lang/Object;

    monitor-enter v0

    .line 128
    :try_start_0
    monitor-enter p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 129
    :try_start_1
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->scheduledPaintEvent:Lorg/microemu/device/ui/EventDispatcher$PaintEvent;

    if-nez v1, :cond_0

    .line 130
    monitor-exit p0
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1

    :try_start_2
    monitor-exit v0
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 141
    :goto_0
    return-void

    .line 134
    :cond_0
    :try_start_3
    monitor-exit p0
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_1

    .line 137
    :try_start_4
    iget-object v1, p0, Lorg/microemu/device/ui/EventDispatcher;->serviceRepaintsLock:Ljava/lang/Object;

    invoke-virtual {v1}, Ljava/lang/Object;->wait()V
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_0
    .catch Ljava/lang/InterruptedException; {:try_start_4 .. :try_end_4} :catch_0

    .line 140
    :goto_1
    :try_start_5
    monitor-exit v0

    goto :goto_0

    :catchall_0
    move-exception v1

    monitor-exit v0
    :try_end_5
    .catchall {:try_start_5 .. :try_end_5} :catchall_0

    throw v1

    .line 134
    :catchall_1
    move-exception v1

    :try_start_6
    monitor-exit p0
    :try_end_6
    .catchall {:try_start_6 .. :try_end_6} :catchall_1

    :try_start_7
    throw v1
    :try_end_7
    .catchall {:try_start_7 .. :try_end_7} :catchall_0

    .line 138
    :catch_0
    move-exception v1

    goto :goto_1
.end method
